package com.itheimamobileguard.receivers;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.telephony.SmsManager;
import android.telephony.TelephonyManager;
import android.util.Log;

public class BootCompleteReceiver extends BroadcastReceiver {

	private static final String TAG = "BootCompleteReceiver";

	@Override
	public void onReceive(Context context, Intent intent) {
		Log.i(TAG, "启动完毕");
		
		SharedPreferences sp =context.getSharedPreferences("config",Context.MODE_PRIVATE);
		boolean protecting = sp.getBoolean("protecting", false);
		if (protecting) {
			String simNum = sp.getString("simNum", "");
			TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
			String tmNum = tm.getSimSerialNumber();
			
			if(simNum.equals(tmNum)){
				Log.i(TAG, "Sim卡未变化");
			}else{
				Log.i(TAG, "Sim未变化");
				String safeNum = sp.getString("safeNum", "");
				SmsManager smsManager = SmsManager.getDefault();
				smsManager.sendTextMessage(safeNum, null, "号码变了", null, null);
			}
		}else {
			Log.i(TAG, "防护未开启");
		}
		
	}

}
